package com.wuax.controller;

import com.wuax.domain.BookType;
import com.wuax.domain.vo.LayTableData;
import com.wuax.domain.vo.Result;
import com.wuax.service.BookTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("/bookType")
public class BookTypeController {

    @Autowired
    private BookTypeService bookTypeService;

    /**
     * 分类列表
     */
    @GetMapping("/list")
    @ResponseBody
    public LayTableData list(BookType bookType) {
        return bookTypeService.list(bookType);
    }

    /**
     * 添加分类
     */
    @PostMapping("/add")
    @ResponseBody
    public Result add(@RequestBody BookType bookType) {
        return bookTypeService.add(bookType);
    }

    /**
     * 修改分类
     */
    @PostMapping("/update")
    @ResponseBody
    public Result update(@RequestBody BookType bookType) {
        return bookTypeService.update(bookType);
    }

    /**
     * 删除分类
     */
    @PostMapping("/delete")
    @ResponseBody
    public Result delete(@RequestParam List<String> bookTypeIds) {
        return bookTypeService.batchDelete(bookTypeIds);
    }

    /**
     * 获取所有的分类，用于图书添加修改的选择
     */
    @GetMapping("/listAll")
    @ResponseBody
    public Result listAll() {
        return bookTypeService.listAll();
    }

    /**
     * 分类页面
     */
    @GetMapping("/bookTypePage")
    public String bookTypePage() {
        return "bookType";
    }
}
